var result = new Object();

/**
 * 查看字段是否为空
 * @return {type} 布尔类型：true代表字段为空，false 代表字段不为空
 */
result.isEmpty = function(varr) {
	if (varr == null || varr == "") {
		return true;
	}
	return false;
}

/**
 * 时间戳转换为YY-MM-DD hh:mm:ss格式
 */
result.timeToCommonFromat = function(time) {
	//将时间戳格式转换成年月日时分秒
	var date = new Date(time);
	var Y = date.getFullYear() + '-';
	var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
	var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';

	var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
	var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
	var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
	var strDate = Y + M + D + h + m + s;
	return strDate;
};

result.dateFromat=function(time,fromatStr){
	var date=new Date(time);
	var Y = date.getFullYear() ;
	var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) ;
	var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) ;
	
	var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours());
	var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes());
	var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
	
	var str=fromatStr
		.replace(/[yY]+/,Y)
		.replace(/M+/,M)
		.replace(/[Dd]+/,D)
		.replace(/[h]+/,h)
		.replace(/[m]+/,m)
		.replace(/[s]+/,s)
		;
	return str;
}

/**
 * 生成uuid
 * @param {Object} len 长度
 */
result.createUUID = function(len) {
	var s = [];
	var hexDigits = "0123456789abcdef";
	for (var i = 0; i < len; i++) {
		s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
	}
	s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
	s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
	s[8] = s[13] = s[18] = s[23];
	var uuid = s.join("");
	return uuid;
}

/**
 * 前往跳转
 * @param {Object} path
 */
result.navTo=function(path){
	uni.navigateTo({
		url:path
	})
}

result.reLaunch=function(path){
	uni.reLaunch({
		url:path
	})
}

/**
 * @param {Object} json
 */
result.newJSON=function(json){
	return JSON.parse(JSON.stringify(json));
}


result.pxToRpx=function(px){
	return px * 750 / wx.getSystemInfoSync().windowWidth;
};


result.rpxToPx=function(rpx){
	return rpx / 750 * wx.getSystemInfoSync().windowWidth;
};

/**
 * 获取系统信息
 */
result.getSystemInfo = function(){
	var systemInfo=uni.getSystemInfoSync();
	return systemInfo;
}

result.readableDistance = function(m){
	var m2=m+"";
	m2=m2.substring(m2.indexOf(".")+1);
	
	var result = {
		unit:'米',
		num: m2
	};
	
	
	if(m>=1000){
		var km=(m/1000);
		var km2=km.toFixed(2)+"";
		var aa=km2.substring(km2.indexOf(".")+1);
		var bb=km2.substring(km2.indexOf(".")+2);
		if(aa<=10){
			km2=km2.substring(0,km2.indexOf("."));
		}
		var result = {
			unit:'公里',
			num: km2
		};
	}
	return result;
}

/**
 * 系统信息
 */
result.systemInfo = result.getSystemInfo();



export default result;
